package top.yokey.shopnc.activity.refund;

import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;

import top.yokey.shopnc.R;
import top.yokey.shopnc.base.BaseApplication;
import top.yokey.shopnc.base.BaseConstant;
import top.yokey.shopnc.base.BaseCountTime;
import top.yokey.base.base.BaseHttpListener;
import top.yokey.shopnc.base.BaseImageLoader;
import top.yokey.base.base.BaseSnackBar;
import top.yokey.base.base.BaseToast;
import top.yokey.shopnc.base.SwipeActivity;
import top.yokey.base.bean.BaseBean;
import top.yokey.base.bean.RefundDetailedBean;
import top.yokey.base.model.MemberRefundModel;
import top.yokey.base.util.JsonUtil;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

/**
 * @author MapStory
 * @ qq 1002285057
 * @ Project https://gitee.com/MapStory/ShopNc-Android
 */

@ContentView(R.layout.activity_refund_detailed)
public class RefundDetailedActivity extends SwipeActivity {

    @ViewInject(R.id.mainLinearLayout)
    private LinearLayoutCompat mainLinearLayout;
    @ViewInject(R.id.mainToolbar)
    private Toolbar mainToolbar;

    @ViewInject(R.id.snTextView)
    private AppCompatTextView snTextView;
    @ViewInject(R.id.reasonTextView)
    private AppCompatTextView reasonTextView;
    @ViewInject(R.id.moneyTextView)
    private AppCompatTextView moneyTextView;
    @ViewInject(R.id.remarkTextView)
    private AppCompatTextView remarkTextView;
    @ViewInject(R.id.zeroImageView)
    private AppCompatImageView zeroImageView;
    @ViewInject(R.id.oneImageView)
    private AppCompatImageView oneImageView;
    @ViewInject(R.id.twoImageView)
    private AppCompatImageView twoImageView;
    private AppCompatImageView[] mainImageView;

    @ViewInject(R.id.storeStateTextView)
    private AppCompatTextView storeStateTextView;
    @ViewInject(R.id.storeRemarkTextView)
    private AppCompatTextView storeRemarkTextView;

    @ViewInject(R.id.adminStateTextView)
    private AppCompatTextView adminStateTextView;
    @ViewInject(R.id.adminRemarkTextView)
    private AppCompatTextView adminRemarkTextView;

    @ViewInject(R.id.paymentTextView)
    private AppCompatTextView paymentTextView;
    @ViewInject(R.id.onlineMoneyTextView)
    private AppCompatTextView onlineMoneyTextView;
    @ViewInject(R.id.preDepositMoneyTextView)
    private AppCompatTextView preDepositMoneyTextView;
    @ViewInject(R.id.rechargeCardMoneyTextView)
    private AppCompatTextView rechargeCardMoneyTextView;

    private String refundIdString;
    private RefundDetailedBean orderRefundDetailedBean;

    @Override
    public void initData() {

        refundIdString = getIntent().getStringExtra(BaseConstant.DATA_ID);
        if (TextUtils.isEmpty(refundIdString)) {
            BaseToast.get().showDataError();
            BaseApplication.get().finish(getActivity());
        }

        mainImageView = new AppCompatImageView[3];
        mainImageView[2] = zeroImageView;
        mainImageView[1] = oneImageView;
        mainImageView[0] = twoImageView;
        mainImageView[0].setVisibility(View.GONE);
        mainImageView[1].setVisibility(View.GONE);
        mainImageView[2].setVisibility(View.GONE);

        setToolbar(mainToolbar, "退款详细");

        getData();

    }

    @Override
    public void initEven() {

    }

    //自定义方法

    private void getData() {

        BaseSnackBar.get().showHandler(mainLinearLayout);

        MemberRefundModel.get().getRefundInfo(refundIdString, new BaseHttpListener() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                String data = baseBean.getDatas().replace("[]", "null");
                orderRefundDetailedBean = JsonUtil.json2Bean(data, RefundDetailedBean.class);
                snTextView.setText(orderRefundDetailedBean.getRefund().getRefundSn());
                reasonTextView.setText(orderRefundDetailedBean.getRefund().getReasonInfo());
                moneyTextView.setText(orderRefundDetailedBean.getRefund().getRefundAmount());
                remarkTextView.setText(orderRefundDetailedBean.getRefund().getBuyerMessage());
                storeStateTextView.setText(orderRefundDetailedBean.getRefund().getSellerState());
                storeRemarkTextView.setText(orderRefundDetailedBean.getRefund().getSellerMessage());
                adminStateTextView.setText(orderRefundDetailedBean.getRefund().getAdminState());
                adminRemarkTextView.setText(orderRefundDetailedBean.getRefund().getAdminMessage());
                if (orderRefundDetailedBean.getDetailArray() != null) {
                    paymentTextView.setText(orderRefundDetailedBean.getDetailArray().getRefundCode());
                    onlineMoneyTextView.setText("￥");
                    onlineMoneyTextView.append(orderRefundDetailedBean.getDetailArray().getPayAmount());
                    preDepositMoneyTextView.setText("￥");
                    preDepositMoneyTextView.append(orderRefundDetailedBean.getDetailArray().getPdAmount());
                    rechargeCardMoneyTextView.setText("￥");
                    rechargeCardMoneyTextView.append(orderRefundDetailedBean.getDetailArray().getRcbAmount());
                }
                if (orderRefundDetailedBean.getPicList() != null) {
                    for (int i = 0; i < orderRefundDetailedBean.getPicList().size(); i++) {
                        mainImageView[i].setVisibility(View.VISIBLE);
                        BaseImageLoader.get().display(orderRefundDetailedBean.getPicList().get(i), mainImageView[i]);
                    }
                }
            }

            @Override
            public void onFailure(String reason) {
                BaseSnackBar.get().show(mainLinearLayout, reason);
                new BaseCountTime(BaseConstant.TIME_COUNT, BaseConstant.TIME_TICK) {
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        getData();
                    }
                }.start();
            }
        });

    }

}
